package cn.loioi.web.controller.admin.masseage;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.github.pagehelper.PageInfo;

import cn.loioi.multi.mysql.model.SysMessage;
import cn.loioi.multi.service.SysMessageService;
import cn.loioi.util.page.JqGrid;
import cn.loioi.web.common.BaseJqGridController;
import cn.loioi.web.components.shiro.common.Permission;

/**
 * <br>
 * (c) Copyright 2016 by <br>
 * @description :未读消息 <br>
 * @file_name :UnreadMessageContorller.java <br>
 * @system_name :multi_project_web <br>
 * @author :yyzh <br>
 * @创建时间 :2016年7月26日 下午1:42:08
 */
@Controller
@RequestMapping("/admin/masseage/unread")
public class UnreadMessageContorller extends BaseJqGridController<SysMessage, SysMessageService> {
	@Autowired
	public UnreadMessageContorller(SysMessageService service) {
		super("admin/masseage/unread/", "message:unread", service);
	}

	@RequestMapping("view.jspx")
	public String view(HttpServletRequest request, HttpServletResponse response, @RequestParam(name = "id", required = true, defaultValue = "0") Integer id, Model model) {
		// 检查用户的权限是否可以访问
		checkPermissionAndSavePage(model, request, Permission.VIEW.parts(_identity));
		// 执行正常操作
		model.addAttribute("record", baseService.findByPrimaryKey(id));
		return returnUrl("view", model);
	}

	@Override
	protected PageInfo<SysMessage> getData(HttpServletRequest request, JqGrid<SysMessage> jqGrid) {
		baseService.setPage(jqGrid);
		return new PageInfo<>(baseService.selectByAccount(getAccount()));
	}
}
